<?php

namespace home\controllers;

use ijony\helpers\Url;
use libs\Utils;
use Yii;
use yii\web\Controller;

/**
 * 控制器基类
 *
 * @inheritdoc
 */
class BaseController extends Controller
{

    public function beforeAction($action)
    {
        if(Utils::isMobile()){
            header("Location: " . Url::getFull(Yii::$app->request->getUrl(), 'wap'));
        }

        return parent::beforeAction($action);
    }

    public function checkActive($index)
    {
        switch($index){
            case 1:

                if(($this->id == 'site' && $this->action->id != 'porsche' && $this->action->id != 'contact' && $this->action->id != 'company') || $this->id == 'page'){
                    return ' active';
                }

                break;
            case 2:

                if($this->id == 'site' && $this->action->id == 'porsche'){
                    return ' active';
                }

                break;
            case 3:

                if($this->id == 'product'){
                    return ' active';
                }

                break;
            case 4:

                if($this->id == 'case'){
                    return ' active';
                }

                break;
            case 5:

                if($this->id == 'timeline'){
                    return ' active';
                }

                break;
            case 6:

                if($this->id == 'site' && $this->action->id == 'contact'){
                    return ' active';
                }

                break;
            case 7:

                if($this->id == 'site' && $this->action->id == 'company'){
                    return ' active';
                }

                break;
            default:
                break;
        }

        return '';
    }
}
